<template>
	<a-collapse default-active-key="1" :bordered="false">
		<template #expandIcon="props">
            <caret-right-outlined :rotate="props.isActive ? 90 : 0"/>
		</template>
		<a-collapse-panel key="1" :header="i18n('auxiliaryLine','辅助线')">
			<a-button @click="add">
                <rx-icon-show icon="icon-linebrush"></rx-icon-show>
                {{i18n('configuration','配置辅助线')}}</a-button>
			<div style="margin-top: 10px;">
				<div class="forewarningConfig-list" v-for="(obj,index) in config.advancedConf.forewarningConfig" :key="index">
					<div>{{obj.name}}</div>
					<div>{{typeAverage(obj.type)}}</div>
					<div v-if="obj.type=='immobilization'">{{obj.immobilizationNumber}}</div>
					<div v-else>{{average(obj.average)}}</div>
				</div>
			</div>
		</a-collapse-panel>
	</a-collapse>
</template>

<script>
import ForewarningCommon from "./forewarning-common.vue";
import {Util} from '@lowcode/jpaas-base-lib';
export default {
	name: "forewarning-config",
	inject:{
		config:{
			default:()=>{
				return {};
			}
		}
	},
	data(){
		return{
			forewarningConfig:[]
		}
	},
	created() {
		if(!this.config.advancedConf.forewarningConfig){
            this.config.advancedConf["forewarningConfig"]=this.forewarningConfig;
		}
	},
	methods:{
		i18n(name,text,key){
			return this.$ti18(name,text,"forewarningLang.forewarningConfig",key);
		},
		add(){
			let self = this;
			let conf = {
				curVm: this,
				component: ForewarningCommon,
				title:this.i18n('auxiliaryLine','辅助线'),
				widthHeight: ['1000px', '500px'],
                zIndex:999,
				data: {
					forewarningConfig: this.config.advancedConf.forewarningConfig,
					measures:this.config.dataSources.measures,
				}
			};
			Util.open(conf, function (action, data) {
				if (action != 'ok') return;
                self.config.advancedConf["forewarningConfig"]=data;
			});
		},
		typeAverage(name){
			if(name=='immobilization'){
				return this.i18n('fixValue','固定值')
			}else {
				return this.i18n('average','平均值')
			}
		},
		average(type){
			let name = '';
			this.config.dataSources.measures.filter(res=>{
				if(type == res.tableName+'_'+res.fieldName){
					name = res.fieldLabel
				}
			})
			return name
		}
	}

}
</script>

<style scoped>
.forewarningConfig-list{
	display: flex;
}
.forewarningConfig-list >div{
	flex: 1;
	margin-right: 10px;
	text-align: left;
}
</style>
